//
//  ChatBaseCell.swift
//  app_rn_frontend
//
//  Created by wanghui on 2018/6/5.
//  Copyright © 2018年 Facebook. All rights reserved.
//

import Foundation
import UIKit

//protocol ChatCellDelegate {
//    func openWebPage(_ param:Param)
//    func openImg(_ param:[String:Any])
//    func resend(_ msg:ChatMessage,cell:UITableViewCell)
//}

protocol ChatCellDelegate {
    func openWebPage(_ param:Param)
    func openImg(_ param:[String:Any])
    func resend(_ msg:ChatMessage,cell:UITableViewCell)
    func deleteDelegate(msg:ChatMessage) //删除
    func reportDelegate(msg:ChatMessage) //举报
    func zhuanfaDelegate(msg:ChatMessage)  //转发
    func addToFavouriteEmotions(msg:ChatMessage) //添加到表情
    func playAndRecordDelegate(msg:ChatMessage)
    func playBackDelegate(msg:ChatMessage)
    func openEmotion(_ param:[String:Any])  //查看表情
    func playVideo(url:NSURL)
    func openRedPacket(msg:ChatMessage) //打开红包
    func addAtInTextviewDelegate(msg:ChatMessage) //添加@功能
}

class ChatBaseCell:UITableViewCell {
    var model:ChatMessage!
    var delegate:ChatCellDelegate?
    
    
    func setup(model:ChatMessage) {
        self.model = model
        self.model.delegate = self
    }
    
    func updateUI(){}
    func transitionToHide(){}
    func transitionToShow(){}
    
    func replaceWithAsterisks(_ input: String) -> String {
        var result = ""
        
        let count = input.unicodeScalars.countByEastAsianWidth()
        
        let total = input.count + count
        
        total.times { _ in
            result.append("*")
        }
//        for scalar in  {
//            switch scalar.isFullwidth {
//            case .fullwidth, .wide:
//                // 对于全角和宽字符（包括中文字符），输出两个星号
//                result.append("*\u{0}")
//            default:
//                // 对于半角和其他字符，输出一个星号
//                result.append("*")
//            }
//        }
        
        return result
    }
    
}

extension ChatBaseCell: ChatMessageDelegate {
    func updateStatus(){
        self.updateUI()
    }
}
